package com.gjj.common;


import org.apache.commons.lang3.StringUtils;
import org.omg.CORBA.PUBLIC_MEMBER;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;

public class PropertiesUtils {

    private static Logger logger = LoggerFactory.getLogger(PropertiesUtils.class);

    private static Properties properties;

    static {
        String filename="config.properties";
        properties = new Properties();
        try {
            properties.load(new InputStreamReader(PropertiesUtils.class.getClassLoader().getResourceAsStream(filename),"UTF-8"));


        } catch (IOException e) {
//            e.printStackTrace();
            logger.error("读取配置文件出错："+e);
        }
    }


    public static String getProperty(String key) {
        String value = properties.getProperty(key.trim());
        if (StringUtils.isBlank(key)) {
            return null;
        }
        return value.trim();

    }

    public static String getProperty(String key, String defaultValue) {
        String value = properties.getProperty(key.trim());
        if (StringUtils.isBlank(key)) {
            value=defaultValue;
        }
        return value.trim();
    }


}
